package com.qf.springbootdemo02.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.springbootdemo02.entity.ResultVO;
import com.qf.springbootdemo02.mapper.IUserMapper;
import com.qf.springbootdemo02.pojo.User;
import com.qf.springbootdemo02.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author q
 * @version V1.0
 * @date 2021/11/22
 **/
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private IUserMapper userMapper;

    @Override
    public ResultVO<IPage> findUserByConditionWithPage(Integer pageNum, Integer pageSize, String condition) {
        IPage<User> page = new Page();
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        QueryWrapper<User> queryWrapper = new QueryWrapper();
        queryWrapper.like("username", condition);
        queryWrapper.or();
        queryWrapper.like("phone",condition);
        //以上三句条件 FROM t_user WHERE username LIKE ? OR phone LIKE ? LIMIT ?,?
        return ResultVO.ok("用户查询成功~", userMapper.selectPage(page, queryWrapper));
    }
}
